﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace Fantacid303.ProcessAffinityControl.Manager.MainWindowViewModels
{
	/// <summary>
	/// Base class for commands
	/// </summary>
	/// <typeparam name="T"></typeparam>
	abstract class MyCommandBase<T> : ICommand where T:INotifyPropertyChanged
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="MyCommandBase&lt;T&gt;"/> class.
		/// </summary>
		/// <param name="model">The model to which this command belongs to.</param>
		public MyCommandBase(T model)
		{
			this.Model = model;
		}

		/// <summary>
		/// Gets the model to which this command belongs to
		/// </summary>
		/// <value>The model to which this command belongs to.</value>
		protected T Model { get; private set; }

		/// <summary>
		/// Occurs when changes occur that affect whether or not the command should execute.
		/// </summary>
		public event EventHandler CanExecuteChanged
		{
			add { CommandManager.RequerySuggested += value; }
			remove { CommandManager.RequerySuggested -= value; }
		}

		/// <summary>
		/// Defines the method that determines whether the command can execute in its current state.
		/// </summary>
		/// <param name="parameter">Data used by the command.  If the command does not require data to be passed, this object can be set to null.</param>
		/// <returns>
		/// true if this command can be executed; otherwise, false.
		/// </returns>
		public abstract bool CanExecute(object parameter);

		/// <summary>
		/// Defines the method to be called when the command is invoked.
		/// </summary>
		/// <param name="parameter">Data used by the command.  If the command does not require data to be passed, this object can be set to null.</param>
		public abstract void Execute(object parameter);
	}
}
